package com.saclub.app.adapter;

import java.util.List;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;

import com.offroader.utils.ViewUtils;
import com.saclub.app.R;
import com.saclub.app.bean.part.News;
import com.saclub.app.utils.ImageUtils;

public class AttitudeListAdapter extends BaseAdapter {
	private List<News> list;

	public AttitudeListAdapter(List<News> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int index) {
		return list.get(index);
	}

	@Override
	public long getItemId(int index) {
		return index;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;

		if (convertView == null || convertView.getTag() == null) {
			convertView = ViewUtils.inflateView(parent.getContext(), R.layout.list_item_attitude);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		News news = list.get(position);

		holder.nameView.setText(news.getNewTitle());
		holder.descView.setText(news.getNewDesc());
		ImageUtils.load(holder.imgView, news.getNewImage());

		return convertView;
	}

	protected class ViewHolder {

		@Bind(R.id.id_list_name)
		TextView nameView;

		@Bind(R.id.id_list_desc)
		TextView descView;

		@Bind(R.id.id_list_img)
		ImageView imgView;

		public ViewHolder(View view) {
			ButterKnife.bind(this, view);
		}
	}

}